const express = require("express");
const app = express();
const path = require("path");
var cors = require("cors");
const file = require("./router/file");
const user = require("./router/admin/user");
const JWT = require("./utils/JWT");
require("./config/db.config");
// 使用swagger API 文档
var swaggerInstall = require("./utils/swagger");
app.use(express.json());
app.use(cors());
app.use(express.urlencoded({ extended: false }));
// app.use((req, res, next) => {
//   const whiteList = ["/admin/user/login"];
//   if (whiteList.includes(req.url) || req.url.includes("swagger")) {
//     next();
//   } else {
//     try {
//       JWT.verify(req.headers.authorization.replace("Bearer ", ""));
//       next();
//     } catch (err) {
//       res.send({
//         message: "用户未登录或者token过期",
//         code: 401,
//         success: false,
//       });
//     }
//   }
// });
app.use("/file", file);
app.use("/admin/user", user);
swaggerInstall(app);
app.use(function (err, req, res, next) {
  res.status(500).send({
    message: err,
    code: 500,
    success: false,
  });
});
app.listen(80, () => {
  console.log(`app listening on port 80`);
});
